#include <stdio.h>
#include <errno.h>
#include <string.h>
#include<stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main()
{
  pid_t id = fork();
  if(id == 0)
  {
    int cnt = 3;
    while(1)
    {
      sleep(3);
      printf("我是一个子进程，pid:%d,ppid:%d\n",getpid(),getppid());
      sleep(1);
      cnt--;
    }
    exit(10);
  }
  while(1)
  {
    int status = 0;
    pid_t rid = waitpid(id,&status,WNOHANG);
    if(rid>0)
    {
      printf("wait success,rid:%d,exit code:%d,exit signal: %d\n",rid,(status>>8)&0xFF,status&0x7F);
    }
    else if(rid == 0)
    {
      printf("本轮调用结束，子进程没有退出\n");
      sleep(1);
    }
    else {
      printf("等待失败\n");
      break;
    }
  }
  return 0;
}
